<#include "../../common/_header.htm">
<div id="hidebox" style="height:100%;width:100%">
    <form action="" method="post" id="editCon">
        <div id="editContent">
            <div class="form-group">
                <span class="iconfont icon-jiufuqianbaoicon14"></span>
                <label class="control-label personName">对象名称：</label>
                <input type="text" class="form-control nameInp" name="personName" placeholder="请输入对象名称" />
            </div>
            <div class="form-group">
				<label class="control-label idType">证件类型：</label>
				<select name="gender" id="idType" class="form-control" style="display: inline-block;width: 220px;margin-left: 20px;border-radius: 5px;">
				</select>
            </div>
            <div class="form-group">
            	<span class="iconfont icon-jiufuqianbaoicon14"></span>
                <label class="control-label idNumber">证件号码：</label>
                <input type="text" class="form-control nameInp" name="idNumber" placeholder="证件号码" required />
            </div>
            <div class="form-group">
                <label class="control-label phoneNumber">联系电话：</label>
                <input type="text" class="form-control nameInp" name="phoneNumber" placeholder="请输入联系电话" oninput="value=value.replace(/[^\d]/g,'')"/>
            </div>
            <div class="form-group">
                <label class="control-label birthPlace">地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址：</label>
                <input type="text" class="form-control nameInp" name="birthPlace" placeholder="请输地址" />
            </div>
            <div class="form-group">
            	<label class="control-label bodyType">人员类型：</label>
				<select name="bodyType" id="bodyType" class="form-control" style="display: inline-block;width: 220px;margin-left: 20px;border-radius: 5px;"></select>
			</div>
            <div class="form-group">
                <label class="control-label remark">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</label>
                <textarea name="remark" class="form-control nameInp" id="remark" style="width: 290px;height: 120px;max-height: 120px;max-width: 290px" data-options="validType:['length[1,1000]']"></textarea>
            </div>
            <div class="editSure">
                <button type="button" onclick="editPersonInformation()" class="el-button el-button--primary editSureBtn">确定</button>
            </div>
        </div>
    </form>
</div>
<script>
	/** 页面加载完毕，回显传值 **/
	var dialog = top.dialog.get(window);
	window.onload = function (){
		$('input[name="personName"]').val(dialog.data.personName);
		$('input[name="idNumber"]').val(dialog.data.idNumber);
		$('input[name="phoneNumber"]').val(dialog.data.phoneNumber);
		$('input[name="birthPlace"]').val(dialog.data.birthPlace);
		$('#remark').val(dialog.data.remark);
		$.ajax({
	        url : "${ctx}/casemanage/findIdType",
	        type : "get",
	        async : false,
	        dataType :'json',
	        success : function (obj) {
	            var select = $("#idType");
	            var open = "<option value=''>-请选择证件类型-</option>";
	            $.each(obj ,function (i,n) {
	                if (dialog.data.idType == n) {
	                    open +='<option value='+n+' selected>'+n+'</option>';
	                }else {
	                    open +='<option value='+n+'>'+n+'</option>';
	                }
	            });
	            select.html(open);
	        }
	    });
		$("#bodyType option").each(function(){
	          var value = $(this).val();   //获取option值  
	          if(dialog.data.bodyType == value){
	        	  $(this).attr("selected",true);
	          }
	    });
		$.ajax({
	        url : "${ctx}/persontype/allpersontype",
	        type : "get",
	        async : false,
	        dataType :'json',
	        success : function (obj) {
	            var select = $("#bodyType");
	            var open = "<option value=''>-请选择人员类型-</option>";
	            $.each(obj ,function (i,n) {
	                if (dialog.data.bodyType == n.personType) {
	                    open +='<option value='+n.personType+' selected>'+n.personType+'</option>';
	                }else {
	                    open +='<option value='+n.personType+'>'+n.personType+'</option>';
	                }
	            });
	            select.html(open);
	        }
	    });
	}
	/*编辑-新增*/
	function editPersonInformation(){
		var personName = $('input[name="personName"]').val();
		var idNumber = $('input[name="idNumber"]').val();
		if(!isNotEmpty(personName) || !notCantSpace(personName)){
			toastr.error("对象名称不能为空或者包含空格","提示信息");
			return false;
		}
		if(!isNotEmpty(idNumber)){
			toastr.error("证件号码不能为空","提示信息");
			return false;
		}
		var data = { 
			"pId" : dialog.data.pid,
			"personName" : personName,
			"oldPersonName" : dialog.data.personName,
			"oldIdNumber" : dialog.data.idNumber,
			"idType" : $('#idType option:selected').val(),
			"idNumber" : idNumber,
			"phoneNumber" : $('input[name="phoneNumber"]').val(),
			"birthPlace" : $('input[name="birthPlace"]').val(),
			"bodyType" : $('#bodyType option:selected').val(),
			"remark" : $('#remark').val(),
			"casemanagerId" : dialog.data.casemanagerId
		};
	    $.ajax({
	    	type : "POST",
	        url : "${ctx}/casemanage/editPersonInformation",
	        contentType: "application/json;charset=UTF-8",
	        data : JSON.stringify(data),
	        success : function (date) {
	        	if(date.result = 'success'){
	        		if(date.data == '0'){
		        		window.parent.location.reload();
	        		}else{
		        		dialog.close();
	        		}
	        	}
	        },
	        error : function() {
	        	toastr.error("保存失败","提示信息");
	        }
	    });
	}

    function isNotEmpty(value) {
        if (value == '') {
            return false;
        }
        if ($.trim(value) == '') {
            return false;
        }
        return true
    };
    
    function notCantSpace(value) {
        if (value == '' || $.trim(value) == '') {
            return true;
        }
        if ($.trim(value).search(/\s/) != -1) {
            return false;
        }
        return true;
    };

</script>
<style>
    input[type="radio"] {
        margin-left: 20px;
    }
    .form-control:focus {
        border-color: #4695ed;
        box-shadow: none;
    }
    .editSure {
        text-align: center;
    }
    button.el-button.el-button--primary.editSureBtn {
        width: 80px;
        height: 32px;
        line-height: 8px;
    }
    span.iconfont.icon-jiufuqianbaoicon14 {
        font-size: 12px;
        margin-left: -17px;
        color: red;
    }
    .form-group{
        margin-left: 25px;
    }
    .nameInp{
        display: inline-block;
        width: 220px;
        margin-left: 20px;
        border-radius: 5px;
    }
    #hidebox {
        top: 23px;
        left: 2%;
        border-radius: 5px;
        background-color:#fff;
        z-Index:9999;
        padding: 10px;
        overflow-y: hidden;
    }
</style>
</body>
</html>